package com.danieldura.highrise.data
{
	
	
	public class Group
	{
		public var id:int;
		public var name:String;
		public var users:Array;
		
		public function parse( data:XML ):void
		{
			id = data.id;
			name = data["name"];
			
			users = new Array();
			for each( var userXML:XML in data.users.user )
			{
				var user:User = new User();
				user.parse( userXML );
				users.push( user );
			}
		}
		
		public function toXML():XML
		{
			var data:XML = new XML( <group /> );
			data.id = id;
			data.name = name;
			
			users.forEach( function( user:User, index:int, array:Array ):void
			{
				data.users.appendChild( user.toXML() );
			} );
			
			return data;
		}
		
		public function toXMLString():String
		{
			return toXML().toXMLString();
		}
				
	}
}

/*
<group>
  <id type="integer">1</id>
  <name>Partners</name>
  <users>
    <user>
      ...
    </user>
    <user>
      ...
    </user>
  </users>
</group>
*/